using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Stratman.Web.VSTS
{
    /// <summary>
    /// A collection of users who are to serve as timesheet administrators.
    /// </summary>
    public class TimesheetAdministratorCollection : ConfigurationElementCollection
    {
        /// <summary>
        /// Creates a new element to add to the collection.
        /// </summary>
        /// <returns>
        /// A new TimesheetAdministrator object.
        /// </returns>
        protected override ConfigurationElement CreateNewElement()
        {
            return new TimesheetAdministrator();
        }

        /// <summary>
        /// Gets value to use as the key for a specific element in this collection.
        /// </summary>
        /// <param name="element">
        /// Element whose key we are to retrieve.
        /// </param>
        /// <returns>
        /// The LoginID property of the specified TimesheetAdministrator object.
        /// </returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((TimesheetAdministrator)element).LoginID;
        }

        /// <summary>
        /// String indexer for the collection; uses the LoginID property of each 
        /// TimesheetAdministrator object as the index.
        /// </summary>
        /// <param name="loginID">
        /// Value of the LoginID property of the TimesheetAdministrator object that we are to 
        /// return.
        /// </param>
        /// <returns>
        /// TimesheetAdministrator object with the specified login ID.
        /// </returns>
        public new TimesheetAdministrator this[string loginID]
        {
            get
            {
                return (base.BaseGet(loginID) as TimesheetAdministrator);
            }

            set
            {
                if (base.BaseGet(loginID) != null)
                    base.BaseRemove(loginID);

                this.BaseAdd(value);
            }
        }

        /// <summary>
        /// Numeric indexer for the collection.
        /// </summary>
        /// <param name="index">
        /// Index in the collection whose contents we are to return.
        /// </param>
        /// <returns>
        /// TimesheetAdministrator object at the specified index.
        /// </returns>
        public TimesheetAdministrator this[int index]
        {
            get
            {
                return (base.BaseGet(index) as TimesheetAdministrator);
            }

            set
            {
                if (base.BaseGet(index) != null)
                    base.BaseRemoveAt(index);

                this.BaseAdd(index, value);
            }
        }
    }
}
